﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Common.Framework.Core.Common
{
    ///<summary>
    /// MongoDB基础类定义，仅包含id和version.
    /// </summary>
    [BsonIgnoreExtraElements(true)]
    [Serializable, JsonObject(MemberSerialization.OptOut)]
    public class BaseMongoEntity
    {
        /// <summary>
        /// 唯一主键
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        ///  mongoDB id : 
        /// 主键( 编码时候请区分到底是业务主键(long类型)   还是mongoDB的主键(string类型)）
        /// </summary>
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        [JsonProperty("_id")]
        public string _id { get; set; }

        /// <summary>
        /// mongodb 文档 自带版本号
        /// </summary>
        [JsonProperty("__v")]
        public int __v { get; set; }

        /// <summary>
        /// 删除标记(0:未删除;1:已删除)
        /// </summary>
        public int DeleteFlag { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [BsonDateTimeOptions(Kind = DateTimeKind.Local), JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        [BsonDateTimeOptions(Kind = DateTimeKind.Local), JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTime UpdateTime { get; set; } = DateTime.Now;
    }
}
